package com.edu.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * RegisterOnline entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.edu.hibernate.RegisterOnline
 * @author MyEclipse Persistence Tools
 */

public class RegisterOnlineDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(RegisterOnlineDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String GENDER = "gender";
	public static final String BIRTHDAY = "birthday";
	public static final String ADDRESS = "address";
	public static final String TEL = "tel";
	public static final String JOB = "job";
	public static final String TIME = "time";
	public static final String COURSE = "course";

	public void save(RegisterOnline transientInstance) {
		log.debug("saving RegisterOnline instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(RegisterOnline persistentInstance) {
		log.debug("deleting RegisterOnline instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public RegisterOnline findById(java.lang.Integer id) {
		log.debug("getting RegisterOnline instance with id: " + id);
		try {
			RegisterOnline instance = (RegisterOnline) getSession().get(
					"com.edu.hibernate.RegisterOnline", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(RegisterOnline instance) {
		log.debug("finding RegisterOnline instance by example");
		try {
			List results = getSession().createCriteria(
					"com.edu.hibernate.RegisterOnline").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding RegisterOnline instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from RegisterOnline as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByGender(Object gender) {
		return findByProperty(GENDER, gender);
	}

	public List findByBirthday(Object birthday) {
		return findByProperty(BIRTHDAY, birthday);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByTel(Object tel) {
		return findByProperty(TEL, tel);
	}

	public List findByJob(Object job) {
		return findByProperty(JOB, job);
	}

	public List findByTime(Object time) {
		return findByProperty(TIME, time);
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findAll() {
		log.debug("finding all RegisterOnline instances");
		try {
			String queryString = "from RegisterOnline";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public RegisterOnline merge(RegisterOnline detachedInstance) {
		log.debug("merging RegisterOnline instance");
		try {
			RegisterOnline result = (RegisterOnline) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(RegisterOnline instance) {
		log.debug("attaching dirty RegisterOnline instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(RegisterOnline instance) {
		log.debug("attaching clean RegisterOnline instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}